﻿using RecruitStudents.Utility.Model;
using DevExpress.XtraEditors.Controls;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using System;
using System.Data;
using System.Windows.Forms;
using RecruitStudents.Utility.Const;
using System.Collections.Generic;
using DevExpress.XtraGrid.Views.Grid;
using System.Drawing;
using RecruitStudents.Utility.Push;
using System.Threading;

namespace RecruitStudents.Client.Examinee
{
    public partial class Examinee_StudentRegistration_New : BaseForm
    {
        public string strExamCity = SessionerHelper.ExamPlaceID;
        ServiceExaminee serviceExam = new ServiceExaminee();
        ServiceComm serviceComm = new ServiceComm();
        public Examinee_StudentRegistration_New()
        {
            InitializeComponent();
            BindExamPlace();
            BindExamProvince();
            gridControl1.DataSource = serviceExam.GetSpecialityKindsDataTable(strExamCity); //绑定gridControl1
            UC_IdCard.Text_KeyPress += UC_IdCard_Text_KeyPress;
        }

        private void BindBKZY()
        {
            DataTable dtExameeSpeciality = serviceExam.GetExameeSpeciality_NetPayFeeInfo_BySignUpID(this.SignUpID);
            if (dtExameeSpeciality != null)
            {
                dtExameeSpeciality.Columns.Add("check", typeof(bool));
                dtExameeSpeciality.Columns.Add("IsFee_First_Name", typeof(string));
                foreach (DataRow dr in dtExameeSpeciality.Rows)
                {
                    if (dr["IsFee_First"].ToString() == "1")
                    {
                        dr["check"] = false;
                        dr["IsFee_First_Name"] = ConstAppConfig.YJF;
                    }
                    else
                    {
                        dr["check"] = true;
                        dr["IsFee_First_Name"] = ConstAppConfig.WJF;
                    }
                }
            }
            gridControl2.DataSource = dtExameeSpeciality;
        }

        #region 绑定生源地下拉列表框
        private void BindExamProvince()
        {
            DataTable dtExamArea = serviceComm.GetExamProvinceDataTable();
            if (dtExamArea != null)
            {
                comboExamArea.Properties.Columns.Clear();
                this.comboExamArea.Properties.Columns.Add(new LookUpColumnInfo("DicNO", 30, "生源地代码"));
                this.comboExamArea.Properties.Columns.Add(new LookUpColumnInfo("DicName", 55, "生源地名称"));
                this.comboExamArea.Properties.ValueMember = "DicNO";
                comboExamArea.Properties.DisplayMember = "DicName";
                this.comboExamArea.Properties.DataSource = dtExamArea;
                comboExamArea.Properties.NullText = "";
            }
        }
        #endregion

        #region 绑定专业类别
        /// <summary>
        /// 绑定专业类别
        /// </summary>
        /// <param name="dtBoundCheckBoxListData"></param>
        private void BoundSpecialityKinds(string strExamPlaceID)
        {
            this.ddlSpec.Properties.DataSource = null;
            //绑定专业类别
            string strSex = GetSex();
            DataTable dtSpecialityKinds = serviceComm.GetSpecialityKindsTableByExamPlaceID(strExamPlaceID, strSex);
            this.ddlSpec.Properties.DataSource = dtSpecialityKinds;
            this.ddlSpec.Properties.Columns.Clear();
            this.ddlSpec.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsNO", 30, "专业代码"));
            this.ddlSpec.Properties.Columns.Add(new LookUpColumnInfo("SpecialityKindsName", 55, "专业名称"));
            this.ddlSpec.Properties.ValueMember = "SpecialityKindsNO";
            this.ddlSpec.Properties.DisplayMember = "SpecialityKindsName";
            this.ddlSpec.Properties.NullText = "";
        }
        #endregion

        private void BindExamPlace()
        {
            #region 绑定考点下拉列表框
            using (DataTable dtProvice = serviceComm.GetExamPlaceTable())
            {
                this.cmboProvice.Properties.Columns.Clear();
                this.cmboProvice.Properties.Columns.Add(new LookUpColumnInfo("ExamPlaceNO", 30, "考点代码"));
                this.cmboProvice.Properties.Columns.Add(new LookUpColumnInfo("ExamPlaceName", 55, "考点名称"));
                this.cmboProvice.Properties.ValueMember = "ExamPlaceNO";
                this.cmboProvice.Properties.DisplayMember = "ExamPlaceName";
                this.cmboProvice.Properties.DataSource = dtProvice;
                this.cmboProvice.Properties.NullText = "";
                this.cmboProvice.EditValue = strExamCity;//设置默认选项（strExamCity是登陆时传过来的值）



                this.ddlExamCity.Properties.Columns.Clear();
                this.ddlExamCity.Properties.Columns.Add(new LookUpColumnInfo("ExamPlaceNO", 30, "考点代码"));
                this.ddlExamCity.Properties.Columns.Add(new LookUpColumnInfo("ExamPlaceName", 55, "考点名称"));
                this.ddlExamCity.Properties.ValueMember = "ExamPlaceNO";
                this.ddlExamCity.Properties.DisplayMember = "ExamPlaceName";
                this.ddlExamCity.Properties.DataSource = dtProvice;
                this.ddlExamCity.Properties.NullText = "";
                this.ddlExamCity.EditValue = strExamCity;//设置默认选项（strExamCity是登陆时传过来的值）
            }
            #endregion
        }

        private void radioGroup1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (radioGroup1.SelectedIndex == 0)
            {
                UC_IdCard.TextEnabled = false;
                btnQuery.Enabled = false;
                btnScan.Enabled = true;
            }
            else
            {
                UC_IdCard.TextEnabled = true;
                btnQuery.Enabled = true;
                btnScan.Enabled = false;
            }
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            ClearTextBox();
            searchInfo();
            UC_IdCard.TextValue = string.Empty;
        }

        #region 获取报名受限制的考点
        private DataTable GetExamPlace_Limit(string strExamCity)
        {
            return serviceExam.GetExamPlace_Limit(strExamCity);
        }
        #endregion

        #region 查询方法
        private void searchInfo()
        {
            modelNotice = null;
            string strIdCard = UC_IdCard.TextValue;
            if (strIdCard == "")
            {
                DevHelper.ShowWarningMessageBox("请填写身份证号码！");
                UC_IdCard.TextFocus();
                return;
            }
            if (!(strIdCard.Length == 15 || strIdCard.Length == 18))
            {
                DevHelper.ShowWarningMessageBox("输入的身份证号码的位数不对！");
                UC_IdCard.TextFocus();
                return;
            }
            if (!CheckIDCard.Check(strIdCard))
            {
                DevHelper.ShowWarningMessageBox("输入的身份证号码【格式错误】，验证不通过！");
                UC_IdCard.TextFocus();
                return;
            }
            //删除上次所拍的照片                
            if (System.IO.File.Exists(Application.StartupPath + "\\zp.bmp"))
            {
                System.IO.File.Delete(Application.StartupPath + "\\zp.bmp");
            }

            DataTable dtLimit = GetExamPlace_Limit(strExamCity);
            if (dtLimit != null && dtLimit.Rows.Count > 0)
            {
                DevHelper.ShowWarningMessageBox("对不起，此考点没有权限现场报名！");
                return;
            }
            DataTable dt = serviceExam.GetExameeByIdentityCard(strIdCard);
            if (dt == null || dt.Rows.Count == 0)  //该考生第一次报名
            {
                InitDataByIdCard(strIdCard);
            }
            else //该考生已报过名
            {
                DataTable dt2 = serviceExam.GetExameeNetPayFeeDataTable_New(strIdCard);
                if (dt2 == null || dt2.Rows.Count == 0)//没有报过任何专业(没有报过任何专业时，则不存在确认缴费的情况)
                {
                    TB_SignUpStudents model = new TB_SignUpStudents();
                    model.SetPropertyValues(dt.Rows[0]);
                    txtIdentityCard.Text = model.IdentityCard;
                    txtBirth.Text = model.Birth;
                    txtLinkMobile.Text = model.LinkMobile;
                    txtName.Text = model.Name;
                    txtNMT_SignUpID.Text = model.NMT_SignUpID;
                    if (model.Sex == "1")
                    {
                        txtSex.Text = "男";
                    }
                    else if (model.Sex == "0")
                    {
                        txtSex.Text = "2";
                    }
                    txtSG.Text = model.Height_ZC;
                    txtSH.Text = model.BodyUpper_ZC;
                    txtTW.Text = model.Hip_ZC;
                    txtTZ.Text = model.Weight_ZC;
                    txtXM.Text = model.ShoeSize_ZC;
                    txtXS.Text = model.BodyLower_ZC;
                    txtXW.Text = model.Breast_ZC;
                    txtYW.Text = model.Waist_ZC;
                    comboExamArea.EditValue = model.ExamProvince;
                    cmboProvice.EditValue = SessionerHelper.ExamPlaceID;
                    this.SignUpID = model.SignUpID;
                    //InitDataByIdCard(strIdCard);
                }
                else
                {
                    bool flagFee = false;
                    //foreach (DataRow dr in dt2.Rows)
                    //{
                    //    if (dr["IsFee_First"].ToSafeString() == "1")
                    //        flagFee = true;
                    //}
                    if (!flagFee)
                    {
                        TB_SignUpStudents model = new TB_SignUpStudents();
                        model.SetPropertyValues(dt.Rows[0]);
                        txtIdentityCard.Text = model.IdentityCard;
                        txtBirth.Text = model.Birth;
                        txtLinkMobile.Text = model.LinkMobile;
                        txtName.Text = model.Name;
                        txtNMT_SignUpID.Text = model.NMT_SignUpID;
                        if (model.Sex == "1")
                        {
                            txtSex.Text = "男";
                        }
                        else if(model.Sex == "0")
                        {
                            txtSex.Text = "2";
                        } 
                        txtSG.Text = model.Height_ZC;
                        txtSH.Text = model.BodyUpper_ZC;
                        txtTW.Text = model.Hip_ZC;
                        txtTZ.Text = model.Weight_ZC;
                        txtXM.Text = model.ShoeSize_ZC;
                        txtXS.Text = model.BodyLower_ZC;
                        txtXW.Text = model.Breast_ZC;
                        txtYW.Text = model.Waist_ZC;
                        comboExamArea.EditValue = model.ExamProvince;
                        cmboProvice.EditValue = SessionerHelper.ExamPlaceID;
                        this.SignUpID = model.SignUpID;
                        BindBKZY();
                    }
                }
            }
        }
        #endregion
        private void InitDataByIdCard(string strIdCard)
        {
            txtIdentityCard.Text = strIdCard;
            //根据身份证地址判断生源地
            GetExamProvinceByIdentityCard();
            string strSex = GetSex();
            if (strSex == "1")
            {
                txtSex.Text = "男";
            }
            else if (strSex == "2")
            {
                txtSex.Text = "女";
            }
            txtBirth.Text = GetBirth();
        }

        #region 根据身份证地址判断生源地
        private void GetExamProvinceByIdentityCard()
        {
            this.comboExamArea.EditValue = txtIdentityCard.Text.Trim().Substring(0, 2) + "0000";
        }
        #endregion

        #region 从身份证号码里提取出 性别
        public string GetSex()
        {
            string strSex = "";
            if (txtIdentityCard.Text.Trim().Length == 18 || txtIdentityCard.Text.Trim().Length == 15)
            {
                if (txtIdentityCard.Text.Trim().Length == 18)
                {
                    if ("13579".IndexOf(txtIdentityCard.Text.Trim().Substring(16, 1)) > -1)
                    {
                        strSex = "1";//男
                    }
                    else
                    {
                        strSex = "2";//女
                    }
                }
                else
                {
                    if ("13579".IndexOf(txtIdentityCard.Text.Trim().Substring(14, 1)) > -1)
                    {
                        strSex = "1";
                    }
                    else
                    {
                        strSex = "2";
                    }
                }
            }
            return strSex;
        }
        #endregion

        #region 从身份证号码里提取 出生年月
        public string GetBirth()
        {
            string strBirth = "";

            if (txtIdentityCard.Text.Trim().Length == 18 || txtIdentityCard.Text.Trim().Length == 15)
            {
                if (txtIdentityCard.Text.Trim().Length == 18)
                {
                    strBirth = txtIdentityCard.Text.Trim().Substring(6, 4) + "-" + txtIdentityCard.Text.Trim().Substring(10, 2) + "-" + txtIdentityCard.Text.Trim().Substring(12, 2);
                }
                else
                {
                    strBirth = "19" + txtIdentityCard.Text.Trim().Substring(6, 2) + "-" + txtIdentityCard.Text.Trim().Substring(8, 2) + "-" + txtIdentityCard.Text.Trim().Substring(10, 2);
                }
            }
            return strBirth;
        }
        #endregion

        #region 手机号码校验
        private void txtLinkMobile_Leave(object sender, EventArgs e)
        {
            if (txtLinkMobile.Text.Trim().Length != 11)
            {
                DevHelper.ShowErrorMessageBox("手机号码的位数不正确！");
                txtLinkMobile.Text = "";
                txtLinkMobile.Focus();
            }
        }
        #endregion

        #region 回车
        private void txtIdCard_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                searchInfo();
            }
        }
        private void txtNMT_SignUpID_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                //txtName.Focus();
            }
        }
        private void txtName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                txtLinkMobile.Focus();
            }
        }
        private void ddlExamCity_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                ddlSpec.Focus();
            }
        }
        private void ddlSpec_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                btnSave.Focus();
            }
        }
        private void UC_IdCard_Text_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                searchInfo();
                UC_IdCard.TextValue = string.Empty;
            }
        }

        #endregion

        private void btnScan_Click(object sender, EventArgs e)
        {

        }

        #region 检查必填项是否填写完整，是否选择重复
        /// <summary>
        /// 检查必填项是否填写完整，是否选择重复，是否输入规范
        /// </summary>
        /// <returns></returns>
        private string CheckData()
        {
            if (txtNMT_SignUpID.Text.Trim() == "")
            {
                txtNMT_SignUpID.Focus();
                return "请填写高考报名号，谢谢！";
            }
            if (!(txtNMT_SignUpID.Text.Trim().Length == 10 || txtNMT_SignUpID.Text.Trim().Length == 11 || txtNMT_SignUpID.Text.Trim().Length == 14))
            {
                txtNMT_SignUpID.Focus();
                txtNMT_SignUpID.SelectAll();
                return "高考报名号是10位或者11位或者14位，谢谢！";
            }
            if (txtName.Text.Trim() == "")
            {
                txtName.Focus();
                return "请填写姓名，谢谢！";
            }
            if (txtIdentityCard.Text.Trim() == "")
            {
                txtIdentityCard.Focus();
                return "请填写身份证号，谢谢！";
            }
            if (comboExamArea.EditValue.ToString().Trim() == "")
            {
                return "请选择生源地，谢谢！";
            }
            if (txtLinkMobile.EditValue.ToString().Trim() == "")
            {
                txtLinkMobile.Focus();
                return "请填写手机号码，谢谢！";
            }
            if (!string.IsNullOrEmpty(txtIdentityCard.Text.Trim()))
            {
                string sex = GetSex();
                if (sex == "2" && (ddlSpec.Text.Trim() == "模特专业"))
                {
                    if (string.IsNullOrEmpty(txtXW.Text.Trim()))
                    {
                        txtXW.Focus();
                        return "请填写胸围，谢谢！";
                    }
                    if (string.IsNullOrEmpty(txtYW.Text.Trim()))
                    {
                        txtYW.Focus();
                        return "请填写腰围，谢谢！";
                    }
                    if (string.IsNullOrEmpty(txtTW.Text.Trim()))
                    {
                        txtTW.Focus();
                        return "请填写臀围，谢谢！";
                    }
                    if (string.IsNullOrEmpty(txtSH.Text.Trim()))
                    {
                        txtSH.Focus();
                        return "请填写上身，谢谢！";
                    }
                    if (string.IsNullOrEmpty(txtXS.Text.Trim()))
                    {
                        txtXS.Focus();
                        return "请填写下身，谢谢！";
                    }
                }
            }
            return "";

        }
        #endregion

        private string SignUpID = string.Empty;

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (ddlExamCity.EditValue == null || ddlExamCity.EditValue.ToSafeString().Length == 0)
            {
                DevHelper.ShowErrorMessageBox("请先选择考点！");
                ddlExamCity.Focus();
                return;
            }
            if (ddlSpec.EditValue == null || ddlSpec.EditValue.ToSafeString().Length == 0)
            {
                DevHelper.ShowErrorMessageBox("请先选择专业！");
                ddlSpec.Focus();
                return;
            }
            string strMessage = CheckData();
            if (strMessage.Length > 0)
            {
                DevHelper.ShowErrorMessageBox(strMessage);
                return;
            }
            string strCity = ddlExamCity.EditValue.ToSafeString();
            string strSpec = ddlSpec.EditValue.ToSafeString();



            TB_SignUpStudents model = null;
            TB_ConsultUsers consultUsersModel = null;
            if (SignUpID == string.Empty)
            {
                CreateSignUpStudents(out model, out consultUsersModel);
            }

            TB_Exam_SignUpStudentsSpeciality examModel = new TB_Exam_SignUpStudentsSpeciality();
            examModel.SignUpID = SignUpID;
            examModel.ExamYear = SessionerHelper.SystemYear;
            examModel.ExamPlaceNO = ddlExamCity.EditValue.ToSafeString();//考点
            examModel.SpecialityKindsNO = ddlSpec.EditValue.ToSafeString();//报考专业
            examModel.OrderNo_First = string.Empty;
            examModel.AppointmentGroup_First = string.Empty;
            examModel.AppointmentGroupTime_First = DateTime.Now;
            examModel.ExamLevel = ConstExamLevel.CS_Value;
            examModel.IsFee_First = ConstAppConfig.WJF_Value;
            examModel.IsActive = "1";
            examModel.SignUpType = ConstPaySource.XC;
            examModel.ExamYear = SessionerHelper.SystemYear;
            examModel.CreatTime = DateTime.Now;
            examModel.ExamState = ConstAppConfig.WKS_Value;
            examModel.IsPass = ConstAppConfig.WTG_Value;
            if (serviceExam.SaveStudentRegistration(model, consultUsersModel, examModel))
            {
                BindBKZY();
            }
        }

        #region 发送消息
        TB_Notice modelNotice = null;
        private void Method()
        {
            if (modelNotice != null)
            {
                #region 推送消息
                PushHelper objJPush = new PushHelper();
                TB_ConsultTitle objTitle = new TB_ConsultTitle();
                TB_ConsultReply objReply = new TB_ConsultReply();
                objTitle.UsersID = modelNotice.SignUpID;
                objTitle.ID = modelNotice.NoticeID;
                objTitle.ConsultTitle = "报名提醒";
                objTitle.TypeID = ConsultType.TZ;
                objJPush.Push(objTitle, objReply);
                #endregion
            }
            modelNotice = null;
        }

        ServiceConsult consultService = new ServiceConsult();

        private void SendAppMessage(string strSignUpID)
        {
            TB_Notice notice = new TB_Notice();
            notice.SignUpID = strSignUpID;
            notice.NoticeType = "private";
            notice.NoticeTitle = "报名提醒";
            notice.Message = "您于" + DateTime.Now.DateTimeToyyyy_MM_dd_HH_mm() + "在现场报名成功！";
            notice.IsRead = "1";
            notice.CreateTime = DateTime.Now;
            notice.IsActive = "1";
            modelNotice = notice;
            List<TB_Notice> list = new List<TB_Notice>();
            if (consultService.SaveNoticeList(list))
            {
                Thread thread = new Thread(new ThreadStart(Method));
                thread.Start();
            }
        }
        #endregion

        private void CreateSignUpStudents(out TB_SignUpStudents model, out TB_ConsultUsers consultUsersModel)
        {
            model = new TB_SignUpStudents();
            model.NMT_SignUpID = txtNMT_SignUpID.Text;
            model.Name = txtName.Text;
            model.IdentityCard = txtIdentityCard.Text;
            model.LinkMobile = txtLinkMobile.Text;
            model.ExamProvince = comboExamArea.EditValue.ToString();//生源地
            model.Height_ZC = txtSG.Text;
            model.Weight_ZC = txtTZ.Text;
            model.Breast_ZC = txtXW.Text;
            model.Waist_ZC = txtYW.Text;
            model.Hip_ZC = txtTW.Text;
            model.ShoeSize_ZC = txtXM.Text;
            model.BodyUpper_ZC = txtSH.Text;
            model.BodyLower_ZC = txtXS.Text;
            model.Birth = txtBirth.Text;
            model.Sex = GetSex();
            model.SignUpDatetime = DateTime.Now;
            model.SignUpType = ConstPaySource.XC;
            model.ExamYear = SessionerHelper.SystemYear;
            SignUpID = model.SignUpID;

            consultUsersModel = new TB_ConsultUsers();
            consultUsersModel.ID = SignUpID;
            consultUsersModel.NickName = SignUpID;
            consultUsersModel.NMT_SignUpID = txtNMT_SignUpID.Text;
            consultUsersModel.IdentityCard = txtIdentityCard.Text;
            consultUsersModel.Name = txtName.Text;
            consultUsersModel.Mobile = txtLinkMobile.Text;
            consultUsersModel.UserType = ConstAppConfig.KS;//考生
            consultUsersModel.State = ConstAppConfig.KY;//可用
            consultUsersModel.CreateDate = DateTime.Now;
            consultUsersModel.IsFee = ConstAppConfig.YJF_Value;
        }
        #region 判断是否是有选择专业
        /// <summary>
        /// 判断是否是有  选择专业
        /// </summary>
        /// <returns></returns>
        private int IsSelectSpeciality()
        {
            int iCount = 0;
            for (int i = 0; i < gridView2.RowCount; i++)
            {
                string val = gridView2.GetRowCellValue(i, gridView2.Columns[0]).ToString();
                string valstr = gridView2.GetRowCellValue(i, gridView2.Columns[1]).ToString();
                if (val != null && val == "True")
                {
                    iCount++;
                }
            }
            return iCount;
        }
        #endregion
        private void btnWCBM_Click(object sender, EventArgs e)
        {
            if (IsSelectSpeciality() == 0)
            {
                DevHelper.ShowErrorMessageBox("请先选择报考专业信息进行缴费！");
                return;
            }
            TB_SignUpStudents model = serviceExam.GetExameeByID(SignUpID);
            if (model != null)
            {
                model.NMT_SignUpID = txtNMT_SignUpID.Text;
                model.Name = txtName.Text;
                model.IdentityCard = txtIdentityCard.Text;
                model.LinkMobile = txtLinkMobile.Text;
                model.ExamProvince = comboExamArea.EditValue.ToString();//生源地
                model.Height_ZC = txtSG.Text;
                model.Weight_ZC = txtTZ.Text;
                model.Breast_ZC = txtXW.Text;
                model.Waist_ZC = txtYW.Text;
                model.Hip_ZC = txtTW.Text;
                model.ShoeSize_ZC = txtXM.Text;
                model.BodyUpper_ZC = txtSH.Text;
                model.BodyLower_ZC = txtXS.Text;
                model.Birth = txtBirth.Text;
                model.Sex = GetSex();
            }
            List<TB_Exam_SignUpStudentsSpeciality> listSpeciality = new List<TB_Exam_SignUpStudentsSpeciality>();
            int iCount = gridView2.RowCount;
            for (int i = 0; i < gridView2.RowCount; i++)
            {
                string val = gridView2.GetRowCellValue(i, gridView2.Columns[0]).ToString();
                if (val != null && val == "True")
                {
                    string strSignUpStudentsSpecialityID = gridView2.GetRowCellValue(i, gridView2.Columns["SignUpStudentsSpecialityID"]).ToString();
                    string strSpecialityKindsNO = gridView2.GetRowCellValue(i, gridView2.Columns["SpecialityKindsNO"]).ToString();
                    TB_Exam_SignUpStudentsSpeciality examModel = new TB_Exam_SignUpStudentsSpeciality();
                    examModel.SignUpStudentsSpecialityID = strSignUpStudentsSpecialityID;
                    examModel.SignUpID = SignUpID;
                    examModel.ExamYear = SessionerHelper.SystemYear;
                    examModel.ExamPlaceNO = strExamCity;//考点
                    examModel.SpecialityKindsNO = strSpecialityKindsNO;
                    examModel.AppointmentGroupTime_First = DateTime.Now;
                    examModel.ExamLevel = ConstExamLevel.CS_Value;
                    examModel.IsFee_First = ConstAppConfig.YJF_Value;
                    examModel.IsActive = "1";
                    examModel.SignUpType = ConstPaySource.XC;
                    examModel.ExamYear = SessionerHelper.SystemYear;
                    examModel.CreatTime = DateTime.Now;
                    examModel.ExamState = ConstAppConfig.WKS_Value;
                    examModel.IsPass = ConstAppConfig.WTG_Value;
                    listSpeciality.Add(examModel);
                }
            }
            bool result = serviceExam.ComplateStudentRegistration(model, listSpeciality);
            if (result)
            {
                DevHelper.ShowInfoMessageBox("考生报名成功！");
                ClearTextBox();
            }
        }

        private void ClearTextBox()
        {
            this.SignUpID = string.Empty;
            txtIdentityCard.Text = string.Empty;
            txtLinkMobile.Text = string.Empty;
            txtName.Text = string.Empty;
            txtNMT_SignUpID.Text = string.Empty;
            txtSex.Text = string.Empty;
            txtSG.Text = string.Empty;
            txtSH.Text = string.Empty;
            txtTW.Text = string.Empty;
            txtTZ.Text = string.Empty;
            txtXM.Text = string.Empty;
            txtXS.Text = string.Empty;
            txtXW.Text = string.Empty;
            txtYW.Text = string.Empty;
            gridControl2.DataSource = null;
        }

        private void gridView2_DoubleClick(object sender, EventArgs e)
        {
            if (gridView2.GetFocusedValue() != null)
            {
                GridView rows = sender as GridView;
                int[] inteurm = rows.GetSelectedRows();
                if (inteurm != null && inteurm.Length > 0)
                {
                    string strSignUpStudentsSpecialityID = rows.Rows[inteurm[0]].DataRow["SignUpStudentsSpecialityID"].ToString();
                    string strExamPlaceNo = rows.Rows[inteurm[0]].DataRow["ExamPlaceNo"].ToString();
                    string strSpecialityKindsNO = rows.Rows[inteurm[0]].DataRow["SpecialityKindsNO"].ToString();

                    DataTable dt = serviceExam.GetExamSigned(strSignUpStudentsSpecialityID);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        DevHelper.ShowErrorMessageBox("该报考专业不能进行补报操作，该考生已经签到！");
                        return;
                    }
                    Examinee_StudentRegistration_Pack option = new Examinee_StudentRegistration_Pack(strSignUpStudentsSpecialityID, GetSex(), strExamPlaceNo, strSpecialityKindsNO);
                    if (option.ShowDialog() == DialogResult.OK)
                    {
                        BindBKZY();
                    }
                    option.Dispose();
                }
            }

        }

        private void ddlExamCity_EditValueChanged(object sender, EventArgs e)
        {
            BoundSpecialityKinds(ddlExamCity.EditValue.ToSafeString());
        }

        private void btnUploadPhoto_Click(object sender, EventArgs e)
        {
            try
            {
                if (System.IO.File.Exists(Application.StartupPath + "\\zp.bmp"))
                {
                    Image image = System.Drawing.Image.FromFile(Application.StartupPath + "\\zp.bmp");

                    Image newImage = new Bitmap(image.Width, image.Height);
                    //将第一个bmp拷贝到bmp2中
                    Graphics draw = Graphics.FromImage(newImage);
                    draw.DrawImage(image, 0, 0);

                    string PicDataD = ImageConvertHelper.ToBase64String(newImage, System.Drawing.Imaging.ImageFormat.Bmp);
                    serviceExam.UploadPhoto(SignUpID, PicDataD);

                    DevHelper.ShowErrorMessageBox("上传成功！");
                }
            }
            catch (Exception ex)
            {
                string essss = ex.Message;
                DevHelper.ShowErrorMessageBox("上传失败！");
            }
        }

        private void txtNMT_SignUpID_Leave(object sender, EventArgs e)
        {
            if (txtNMT_SignUpID.Text == "")
            {
                return;
            }
            if (txtNMT_SignUpID.Text.Trim().Length == 10 || txtNMT_SignUpID.Text.Trim().Length == 11 || txtNMT_SignUpID.Text.Trim().Length == 14)
            {
                string strYKZ = txtNMT_SignUpID.Text;
                DataTable dt = serviceExam.GetStudentsInfoByYKZ(strYKZ);
                if (dt == null || dt.Rows.Count == 0)
                {
                    DataTable dtP = serviceComm.GetProviceTable(strYKZ);
                    if (dtP == null || dtP.Rows.Count == 0)
                    {
                        DevHelper.ShowWarningMessageBox("高考报名号格式不正确，无法解析生源地！");
                        txtNMT_SignUpID.Text = string.Empty;
                        return;
                    }
                    else
                    {
                        foreach (DataRow dr in dtP.Rows)
                        {
                            if (dr["Message"].ToSafeString() != "")
                            {
                                DevHelper.ShowWarningMessageBox(dr["Message"].ToSafeString());
                                txtNMT_SignUpID.Text = string.Empty;
                                return;
                            }
                        }
                        this.comboExamArea.Properties.DataSource = null;
                        this.comboExamArea.Properties.Columns.Clear();
                        this.comboExamArea.Properties.Columns.Add(new LookUpColumnInfo("ProviceNo", 30, "生源地代码"));
                        this.comboExamArea.Properties.Columns.Add(new LookUpColumnInfo("ProviceName", 55, "生源地名称"));
                        this.comboExamArea.Properties.ValueMember = "ProviceNo";
                        this.comboExamArea.Properties.DisplayMember = "ProviceName";
                        this.comboExamArea.Properties.DataSource = dtP;
                        this.comboExamArea.EditValue = dtP.Rows[0]["ProviceNo"].ToSafeString();



                        if (dtP.Rows.Count > 1)
                        {
                            this.comboExamArea.Enabled = true;
                        }
                        else
                        {
                            this.comboExamArea.Enabled = false;
                        }
                    }
                }
                else
                {
                    DevHelper.ShowWarningMessageBox("该高考报名号已经存在，请确认！");
                    txtNMT_SignUpID.Text = string.Empty;
                    return;
                }

            }
            else
            {
                DevHelper.ShowWarningMessageBox("高考报名号【位数】不正确！");
                txtNMT_SignUpID.SelectAll();
                txtNMT_SignUpID.Focus();
                return;
            }
        }
    }
}
